package com.shinvent.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.shinvent.common.Logger;
import com.shinvent.dao.BaseDao;
import com.shinvent.dao.T_INVENTORYDao;

public class Delete extends HttpServlet {
	private static final long serialVersionUID = 1L;

    public Delete() {
        super();
        // TODO Auto-generated constructor stub
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("plain/text");
	    PrintWriter out = response.getWriter();
		T_INVENTORYDao inventoryDao = null;
		
		try{
			String objectID = request.getParameter("oid");
			
			inventoryDao = new T_INVENTORYDao();
			inventoryDao.query("ORDER_ID = " + objectID);
			if(inventoryDao.gotoNext()){
				if(inventoryDao.delete()){
					out.print("OK");
				}else{
					out.print("ERROR");
				}
			}else{
				out.print("ERROR");
			}
			release(inventoryDao);
		}catch(Exception e){
			e.printStackTrace();
			Logger.logError(e);
			out.print("ERROR");
		}finally{
			release(inventoryDao);
		}
		
	}

	
	private void release(BaseDao dao){
		try{
			dao.close();
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
}
